<?php
/**
 * 图标管理
 * Created by gii.
 * User: Gii
 * Date: 2022/03/18
 * Time: 16:49
 */

namespace App\Models\Models\System;

use App\Models\Traits\Common;
use Illuminate\Database\Eloquent\Model;

class SystemIcon extends Model
{
	use Common;

    /**
     * 获取where条件
     * @param array $data 参数数组
     * @param array $fields 要处理的字段
     * @return array
     */
    public static function getSelfWhereCommon(Array $data , $fields = []) {
        $keys = array_keys($data);
        if($fields) {
            //去掉data里面fields没指定的字段
            $keys = array_intersect($keys , $fields);
        }
        $where = [];
        foreach($keys as $key) {
            $val = $data[$key] ?? '';
            if($val === '') continue; //过滤空值
            switch ($key) {
                case 'icon':
                    $where[] = [$key, 'like', "%" .$val. "%"];
                    break;
                default:
                    $where[] = [$key, '=', $val];
            }
        }
        return $where;
    }

    public static function getAllForm() {
        $data = self::getAllCommon();
        $res = [];
        foreach($data as $v) {
            $res[$v['icon']] = $v['desc'];
        }
        return $res;
    }
}
